<?php
declare (strict_types=1);

namespace app\mall\model;

use app\mall\model\traits\EnableTrait;
use app\mall\model\traits\GoodsTrait;
use think\Model;

/**
 * @mixin Model
 * @property int stock
 * @property int id
 * @property float price
 */
class MallGoodsStock extends MallBase
{
    use GoodsTrait;
    use EnableTrait;

    public function setSpecAttr($value, $data)
    {
        return json_encode($value, JSON_UNESCAPED_UNICODE);
    }

    public function getSpecAttr($value, $data)
    {
        return json_decode($value, true);
    }

    public function isEnough($nums = 1)
    {
        return $this->stock > $nums;
    }
}
